package com.ws.universal.tools.takephoto.multipleimageselect.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.ws.universal.tools.R;
import com.ws.universal.tools.takephoto.multipleimageselect.models.Album;
import com.ws.universal.tools.utils.LogcatUtils;

import java.util.ArrayList;

/**
 * @author:ws
 * @date: 2020/9/1 11:54
 * @desc
 */
public class CustomAlbumSelectAdapter extends CustomGenericAdapter<Album> {


    public CustomAlbumSelectAdapter(Context context, ArrayList<Album> albums) {
        super(context, albums);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.grid_view_item_album_select, null);

            viewHolder = new ViewHolder();
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.image_view_album_image);
            viewHolder.textView = (TextView) convertView.findViewById(R.id.text_view_album_name);
            viewHolder.type = (ImageView) convertView.findViewById(R.id.image_view_type);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.imageView.getLayoutParams().width = size;
        viewHolder.imageView.getLayoutParams().height = size;
        LogcatUtils.i(" type " + arrayList.get(position).type);
        if (arrayList.get(position).type.equals("video/mp4")) {
            viewHolder.type.setVisibility(View.VISIBLE);
        } else {
            viewHolder.type.setVisibility(View.GONE);
        }
        viewHolder.textView.setText(arrayList.get(position).name);
        RequestOptions options = new RequestOptions().centerCrop().placeholder(R.drawable.image_placeholder);
        Glide.with(context).load(arrayList.get(position).cover).apply(options).into(viewHolder.imageView);
        return convertView;
    }

    private static class ViewHolder {
        public ImageView imageView;
        public TextView textView;
        public ImageView type;
    }
}
